﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace StoreWeb
{
    public partial class index : System.Web.UI.Page
    {
        public string username, loginname, dealers;

        Maticsoft.BLL.UserAdmin Userbll = new Maticsoft.BLL.UserAdmin();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                HttpCookie cookie = Request.Cookies["UserLogin"];

                ltrolename.Text = Server.UrlDecode(cookie.Values["rolename"]);
                hidrolecode.Value = Server.UrlDecode(cookie.Values["rolecodemenber"]);
                rptone.DataSource = getrightsbyrolecode(hidrolecode.Value, 1, null);
                rptone.DataBind();

                username = Server.UrlDecode(cookie.Values["username"]);
                loginname = Server.UrlDecode(cookie.Values["loginname"]);
                dealers = Server.UrlDecode(cookie.Values["dmname"]);
            }
        }
        private static List<Maticsoft.Model.Rights> getrightsbyrolecode(string rolecode, int ltype, string parentcode)
        {
            Maticsoft222.BLL.UserRole bll = new Maticsoft222.BLL.UserRole();
            if (string.IsNullOrEmpty(parentcode))
                return bll.GetModelList(rolecode).Where(c => c.ltype == ltype).ToList();
            else
                return bll.GetModelList(rolecode).Where(c => c.ltype == ltype && c.parentcode == parentcode).ToList();
        }
        protected void rptone_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater rpt = (Repeater)e.Item.FindControl("rpttrue");
                HiddenField hidparentcode = (HiddenField)e.Item.FindControl("hidparentcode");
                rpt.DataSource = getrightsbyrolecode(hidrolecode.Value, 2, hidparentcode.Value);
                rpt.DataBind();

            }
        }
    }
}